package tech.aistar.corejava.day15.homework;

/**
 * @Author: lya
 * @Description: 本类的作用描述:
1. 写三线程，
一个线程负责打印_A
另一个线程负责打印_B
另一个线程负责打印_C
 *
 * @CreateDate: 2019/8/5
 * @Version: 1.0
 */
public class test {
    public static void main(String[] args) {
        Painter1 p = new Painter1();
        new Thread() {
            @Override
            public void run() {
                p.print01();
            }
        }.start();

        new Thread() {
            @Override
            public void run() {
                p.print02();
            }
        }.start();
    }
}

class Painter1 {

    public void print01() {
        synchronized (this) {  //同步代码块,锁对象为调用这个方法的对象

                System.out.print("_A");

                    notifyAll();
                    try {
                        wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
        }

    }

    public void print02() {
        synchronized (this) {

                System.out.print("_B");
                notifyAll(); //唤醒所有线程
                try {
                    wait();   //让该线程等待
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

        }

    }
}
